const express = require('express')
var SqliteDB = require('../db/sqlite.js').SqliteDB;
console.log("进来了")

const router = express.Router()

var file = "./paxy.db3";

var sqliteDB = new SqliteDB(file);


// var createTileTableSql = "create table if not exists tiles(level INTEGER, column INTEGER, row INTEGER, content BLOB);";

// var createLabelTableSql = "create table if not exists labels(level INTEGER, longitude REAL, latitude REAL, content BLOB);";

// sqliteDB.createTable(createTileTableSql);

// sqliteDB.createTable(createLabelTableSql);

//  var a="insert into account(login_name,pasword) values(?,?)" 

//  var b="insert into account(login_name,pasword) values('047','369')"  
// var tileData = [["wujie","123"]];

// var insertTileSql = "insert into tiles(level, column, row) values(?, ?, ?)";

// // sqliteDB.insertData(a, tileData);
function addUser(username, password) {
    var b = `insert into account(login_name,pasword) values(${username},${password})`

    sqliteDB.executeSql(b);

    sqliteDB.close();
}
router.post('/add', (req, res) => {

    const { username, password } = req.body
    console.log(username, password)
    async function find() {
        var b = `select * from account where login_name='${username}' and  pasword='${password}'`

        let a = await sqliteDB.executeSql(b);
        console.log("a", a)
        res.send(a)
    }

    find()
   



})

// sqliteDB.executeSql(b); //新增用户明密码

// var querySql = 'select * from records_management ';

// sqliteDB.queryData(querySql, dataDeal);



/// update data.

// var updateSql = 'update tiles set level = 3 where level = 3 and column = 20 and row = 10';

// sqliteDB.executeSql(updateSql);



/// query data after update.

// querySql = "select * from tiles where level = 2";

// sqliteDB.queryData(querySql, dataDeal);



// sqliteDB.close();



// function dataDeal(objects){

//     for(var i = 0; i < objects.length; ++i){

// //         console.log(666,objects[i]);

//     }

// }

// const router = express.Router()
module.exports = router